/**
 * Description:
 *
 * @author      Eden
 * @datetime    2016/12/4 22:26
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

(function () {

    "use strict";

    var api = {
        editUrl: "admin/user/editPassword"
    };

    sm.controller('admin-user-password', ['$scope', '$http', 'Modal', function ($scope, $http, Modal) {

        $scope.detail = {
            password: "",
            newPassword: "",
            rePassword: ""
        }

        $scope.save = function () {
            if (!$scope.detail.password || !$scope.detail.newPassword || !$scope.detail.rePassword) {
                Modal.error('有必填参数没有填写');
                return false;
            }

            if ($scope.detail.newPassword != $scope.detail.rePassword) {
                Modal.error('新密码不相等');
                return false;
            }

            if ($scope.detail.newPassword.length < 6) {
                Modal.error('密码长度不符');
                return false;
            }

            $http.post(api.editUrl, $scope.detail).success(function (res) {
                if (res.state) {
                    Modal.success('修改成功');
                } else {
                    Modal.error(res.error ? res.error : "修改失败");
                }
            });

        };

    }]);

})();